﻿ 
using System;

class Calculator
{
    static void Main()
    {
        while (true)
        {
            Console.WriteLine("简单计算器");
            Console.WriteLine("--------------");
            Console.WriteLine("选择操作:");
            Console.WriteLine("1. 加法");
            Console.WriteLine("2. 减法");
            Console.WriteLine("3. 乘法");
            Console.WriteLine("4. 除法");
            Console.WriteLine("5. 退出");

            // 读取用户选择
            Console.Write("请输入选项 (1-5): ");
            int choice;
            if (!int.TryParse(Console.ReadLine(), out choice) || choice < 1 || choice > 5)
            {
                Console.WriteLine("无效的选项，请重新输入。");
                continue;
            }

            // 执行相应的操作
            if (choice == 5)
            {
                Console.WriteLine("程序已退出。");
                break;
            }

            Console.Write("请输入第一个操作数: ");
            double operand1;
            if (!double.TryParse(Console.ReadLine(), out operand1))
            {
                Console.WriteLine("无效的输入，请输入一个有效的数字。");
                continue;
            }

            Console.Write("请输入第二个操作数: ");
            double operand2;
            if (!double.TryParse(Console.ReadLine(), out operand2))
            {
                Console.WriteLine("无效的输入，请输入一个有效的数字。");
                continue;
            }

            double result = 0;

            // 执行相应的运算
            switch (choice)
            {
                case 1:
                    result = operand1 + operand2;
                    break;
                case 2:
                    result = operand1 - operand2;
                    break;
                case 3:
                    result = operand1 * operand2;
                    break;
                case 4:
                    if (operand2 != 0)
                        result = operand1 / operand2;
                    else
                        Console.WriteLine("除数不能为零。");
                    break;
                default:
                    Console.WriteLine("无效的选项，请重新输入。");
                    continue;
            }

            Console.WriteLine($"结果: {result}");
        }
    }
}
